<?
/*--|   HOME
  Software: Socially
   Version: 1.0
   Contact: http://socially.googlecode.com
      Info: http://socially.googlecode.com
   Support: http://socially.googlecode.com
--------------------------------------------------------------------------
    Author: goker.cebeci | http://gokercebeci.com
--------------------------------------------------------------------------
   License: Distributed under the GNU General Public License (GPL)
            http://www.gnu.org/licenses/gpl.html
 This program is distributed in the hope that it will be useful - WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 FITNESS FOR A PARTICULAR PURPOSE.
-------------------------------------------------------------------------*/
class home {
    const PATH = 'data/home/';
/* -----------------------------------------------------------------------
    EDITORIAL FUNCTIONS
 ------------------------------------------------------------------------*/
    /**
     * LAYOUT
     *
     * @param array $a [aplication list]
     * @return result object
     */
    public static function layout($a, $cmd = 'get'){
        switch ($cmd){
            case 'set':
                if(!EDITOR) return common::result(600,_('Access denied'));
                if(!is_writable(self::PATH)) return common::result(800,_('Writing is not permited'));
                file_put_contents(self::PATH.'layout.json', json_encode($a['layout']));
                cache::set('home[layout]', json_encode($a['layout']));
                return common::result(200,_('Home page layout has beed saved.'));
            break;
            case 'get':
                //$layout = json_decode(cache::get('home[layout]'));
                if($layout) return $layout;
                if($a) {
                    $layout = json_decode(@file_get_contents(self::PATH.'layout.json'));
                    foreach ($a as $i) {
                        $layout->content->$i = $layout->content->$i ? 1 : 0;
                        $layout->aside->$i = $layout->aside->$i ? 1 : 0;
                    }
                }
                cache::set('home[layout]', json_encode($layout));
                return $layout;
            break;
        }
    }
    public static function search(){}
    public static function sitemap(){}
}
?>
